package com.system.dao.impl;



import com.system.config.Jdbc;
import com.system.dao.AssignName;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashSet;

public class AssignNameMapper implements AssignName {
    private final Jdbc jb;

    public AssignNameMapper() {
        this.jb = new Jdbc();
    }

    @Override
    public boolean isInspect(String email) {
        try {
            String sql = "select *  from user where email='"+email+"'";
            ResultSet rs = this.jb.getStmt().executeQuery(sql);
            if (rs.next()) return true;
        }catch (SQLException e)
        {
            throw new RuntimeException(e);
        }
        return false;
    }


    @Override
    public  HashSet<String> loadALLName() {
        HashSet<String> set = new HashSet<>();
        try {
            String sql = "select * from memouser";
            ResultSet rs = this.jb.getStmt().executeQuery(sql);
            while (rs.next())
            {
                set.add(rs.getString("name"));
            }
        }catch (SQLException e)
        {
            throw new RuntimeException(e);
        }
        return set;
    }
}
